package com.zy.crm.workbench.controller;


import com.zy.crm.vo.Message;
import com.zy.crm.vo.PaginationVo;
import com.zy.crm.workbench.domain.Owner;
import com.zy.crm.workbench.domain.ship_zl;
import com.zy.crm.workbench.service.ship_zlService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author CYH
 * 2021年11月13日测试功能完成
 */
//
@Controller
public class ship_zlController {

    @Resource
    private ship_zlService ship_zlService;


    // 添加用户信息，无误
    @RequestMapping("/workbench/ship_zl/saveShip.do")
    @ResponseBody
    public Object saveActivity(ship_zl ship_zl){
        //测试
        System.out.println("进入保存成功，前端无误，继续排查");
        System.out.println(ship_zl);
        // 得到保存结果
        Message msg = ship_zlService.saveShip_zl(ship_zl);

        return msg;
    }

    @RequestMapping("/workbench/ship_zl/pageList.do")
    @ResponseBody
    // 查询用分页
    public Object getPageList(String pageNo, String pageSize,ship_zl ship_zl){
        //System.out.println("进入了查询界面");

       // System.out.println("测试数据传输了什么"+ship_zl);
        PaginationVo<ship_zl> paginationVo = ship_zlService.getPageList(pageNo,pageSize,ship_zl);
        System.out.println(paginationVo);
        return paginationVo;
    }

    // 删除根据id,无误
    @RequestMapping("/workbench/ship_zl/delete.do")
    @ResponseBody
    public Message deleteActivity(HttpServletRequest request) {

        // 拿到ActivityId数组
        String ship_zlIds[] = request.getParameterValues("id");
        System.out.println("第一条数据是："+ship_zlIds);
        // 根据id数组删除市场活动cce5c8636660495d839bd0f661cc5d66
                           //cce5c8636660495d839bd0f661cc5d665
        Message msg = ship_zlService.deleteShip_zl(ship_zlIds);
        System.out.println("删除成功");
        return msg;
    }


    // 修改市用户数据依据id,测试中
    @RequestMapping("/workbench/ship_zl/updateShip.do")
    @ResponseBody
    public Message updateActivityById(ship_zl ship_zl){
       // System.out.println("成功添加数据进入了修改数据");
        //System.out.println("测试传入的数据是否异常"+ship_zl);
        //测试到传入的name和id都是null，估计是前端问题
        Message msg = ship_zlService.updateShip_zlById(ship_zl);
        //System.out.println("成功出来");
        return msg;

    }

    //根据用户id查询一条用户信息
    @RequestMapping("/workbench/ship_zl/getShipById.do")
    @ResponseBody
    public Map<String , Object> getShip_zlById(String id){
        Map<String , Object> map = new HashMap<>();
        System.out.println("测试获取原来的信息"+id);
        // 查询到市场活动信息
        ship_zl ship_zl = ship_zlService.getShip_zlById(id);
        //测试是否有结果返回,结果很明显是进入业务层出错，继续测试
        //System.out.println("测试是否有结果返回");
        // 封装入map
        //System.out.println(ship_zl);
        map.put("ship_zlById",ship_zl);//测试结果是user里面有name的，是前端有问题

        return  map;
    }

    @RequestMapping("/workbench/ship_zl/pageList1.do")//报表打印
    @ResponseBody
    // 打印数据
    public Message getPageList1(ship_zl center) throws IOException {

        List<ship_zl> list = ship_zlService.getPrint(center);
        //System.out.println("获取的数据是"+list);
        Message msg = new Message();

        String path = "D:\\ssm项目\\crm-master -day11\\";
        Workbook workbook = new HSSFWorkbook();//工作簿
        Sheet sheet = workbook.createSheet("船只资料登记表");//工作表
        //（1，1）
        Row row1 = sheet.createRow(0);//第一行数据
        Cell cell11 = row1.createCell(0);//第一列数据
        cell11.setCellValue("序号");//内容
        //(1,2)
        Cell cell12 = row1.createCell(1);//第二列数据
        cell12.setCellValue("船名");//内容

        Cell cell13 = row1.createCell(2);//第三列数据
        cell13.setCellValue("登记编号");//内容
        Cell cell14 = row1.createCell(3);//第四列数据
        cell14.setCellValue("初次登记号");//内容
        Cell cell15 = row1.createCell(4);//第五列数据
        cell15.setCellValue("曾用名");//内容
        Cell cell16 = row1.createCell(5);//第三列数据
        cell16.setCellValue("船籍港");//内容
        Cell cell17 = row1.createCell(6);//第四列数据
        cell17.setCellValue("原船籍港");//内容
        Cell cell18 = row1.createCell(7);//第五列数据
        cell18.setCellValue("船舶呼号");//内容
        Cell cell19 = row1.createCell(8);//第四列数据
        cell19.setCellValue("IOM编号");//内容
        Cell cell110 = row1.createCell(9);//第五列数据
        cell110.setCellValue("船舶种类");//内容
        Cell cell111 = row1.createCell(10);//第二列数据
        cell111.setCellValue("材料");//内容

        Cell cell112 = row1.createCell(11);//第三列数据
        cell112.setCellValue("建船地点");//内容
        Cell cell113 = row1.createCell(12);//第四列数据
        cell113.setCellValue("建船时间");//内容
        Cell cell114 = row1.createCell(13);//第五列数据
        cell114.setCellValue("船舶价值");//内容
        Cell cell115 = row1.createCell(14);//第三列数据
        cell115.setCellValue("总长");//内容
        Cell cell116 = row1.createCell(15);//第四列数据
        cell116.setCellValue("型宽");//内容
        Cell cell117 = row1.createCell(16);//第五列数据
        cell117.setCellValue("型深");//内容
        Cell cell118 = row1.createCell(17);//第四列数据
        cell118.setCellValue("总吨");//内容
        Cell cell119 = row1.createCell(18);//第五列数据
        cell119.setCellValue("净吨");//内容
        Cell cell120 = row1.createCell(19);//第三列数据
        cell120.setCellValue("主机种类");//内容
        Cell cell121 = row1.createCell(20);//第四列数据
        cell121.setCellValue("主机数目");//内容
        Cell cell122 = row1.createCell(21);//第五列数据
        cell122.setCellValue("功率");//内容
        Cell cell123 = row1.createCell(22);//第三列数据
        cell123.setCellValue("推进器种类");//内容
        Cell cell124 = row1.createCell(23);//第四列数据
        cell124.setCellValue("推进器数目");//内容
        Cell cell125 = row1.createCell(24);//第五列数据
        cell125.setCellValue("船舶所有人");//内容
        Cell cell126 = row1.createCell(25);//第四列数据
        cell126.setCellValue("船舶所有人地址");//内容
        Cell cell127 = row1.createCell(26);//第五列数据
        cell127.setCellValue("法定代表姓名");//内容
        Cell cell128 = row1.createCell(27);//第四列数据
        cell128.setCellValue("取得所有权日期");//内容
        Cell cell129 = row1.createCell(28);//第五列数据
        cell129.setCellValue("签证单位");//内容
        Cell cell130 = row1.createCell(29);//第四列数据
        cell130.setCellValue("编号");//内容
        Cell cell131 = row1.createCell(30);//第五列数据
        cell131.setCellValue("发证日期");//内容
        String arr[][] = new String[list.size()][31];

        for (int i = 0; i < list.size(); ++i) {
            arr[i][0] = list.get(i).getId();
            arr[i][1] = list.get(i).getName();
            arr[i][2] = list.get(i).getNum();
            arr[i][3] = list.get(i).getEverNum();
            arr[i][4] = list.get(i).getEverName();
            arr[i][5] = list.get(i).getPort();
            arr[i][6] = list.get(i).getEverPort();
            arr[i][7] = list.get(i).getTel();

            arr[i][8] = list.get(i).getIMO_num();
            arr[i][9] = list.get(i).getType();
            arr[i][10] = list.get(i).getCailiao();
            arr[i][11] = list.get(i).getBuild_place();
            arr[i][12] = list.get(i).getBuild_time();
            arr[i][13] = list.get(i).getValue();
            arr[i][14] = list.get(i).getLength();
            arr[i][15] = list.get(i).getWidth();
            arr[i][16] = list.get(i).getDepth();
            arr[i][17] = list.get(i).getAllWeight();
            arr[i][18] = list.get(i).getWeight();
            arr[i][19] = list.get(i).getZhuji_type();
            arr[i][20] = list.get(i).getTel();
            arr[i][21] = list.get(i).getZhuji_num();
            arr[i][22] = list.get(i).getTuijinqi_type();
            arr[i][23] = list.get(i).getTuijinqi_num();
            arr[i][24] = list.get(i).getBoss();
            arr[i][25] = list.get(i).getHome();
            arr[i][26] = list.get(i).getOwner();
            arr[i][27] = list.get(i).getBelong_time();
            arr[i][28] = list.get(i).getGovernment();
            arr[i][29] = list.get(i).getBianhao();
            arr[i][30] = list.get(i).getBeginTime();

        }


        for (int i = 1; i <= list.size(); ++i) {
            Row row = sheet.createRow(i);//第I+1行数据
            for (int j = 0; j <31; ++j) {
                Cell cell = row.createCell(j);
                cell.setCellValue(arr[i - 1][j]);//
            }

        }

        //生成一个表
        FileOutputStream fileOutputStream= new FileOutputStream(path+"船只资料登记表.xls");

        workbook.write(fileOutputStream);
        //关闭流
        workbook.close();

        System.out.println("成功生成");


        msg.setSuccess(true);

        return  msg;

    }
}


















